import { request } from './request'

// 请求详情数据方法
export function getDetail (iid) {
  return request({
    url: '/detail',
    params: {
      iid
    }
  }).catch(err => err)
}

// 请求推荐模块数据方法
export function getRecommend () {
  return request({
    url: '/recommend'
  }).catch(err => err)
}

// TODO: 面向对象开发: 将需要的商品信息整合整一个类
// 商品信息
export class GoodsInfo {
  constructor (itemInfo, columns, services) {
    // 商品标题
    this.title = itemInfo.title
    // 商品排序
    this.desc = itemInfo.desc
    // 新价格
    this.newPrice = itemInfo.price
    // 旧价格
    this.oldPrice = itemInfo.oldPrice
    // 折扣
    this.discount = itemInfo.discountDesc
    // 折扣盒子背景颜色
    this.discountbgColor = itemInfo.discountBgColor
    // 专栏: 销量, 收藏, 快递方式
    this.columns = columns
    // 服务项目
    this.services = services
    // 打折后的当前价格
    this.nowPrice = itemInfo.lowNowPrice
  }
}

// 商家信息
export class Shop {
  constructor (shopInfo) {
    this.logo = shopInfo.shopLogo
    this.name = shopInfo.name
    this.fans = shopInfo.cFans
    this.sells = shopInfo.cSells
    this.score = shopInfo.score
    this.goodsCount = shopInfo.cGoods
  }
}

// 商品介绍以及图片信息
export class DetailInfo {
  constructor (detailInfo) {
    this.detailImage = detailInfo.detailImage
    this.desc = detailInfo.desc
  }
}

// 商品参数
export class GoodsParams {
  constructor (info, rule) {
    // iamges可由没有值(某些商品有)
    this.images = info.images ? info.images[0] : []
    this.infos = info.set
    this.sizes = rule.tables
  }
}

// 用户信息以及评价
export class UserReview {
  constructor (review) {
    // 传递过来的其实是有一个对象
    if (Object.keys(review).length) {
      this.userAvatar = review.user.avatar
      this.userName = review.user.uname
      this.userRate = review.content
      this.created = review.created
      this.style = review.style
    }
  }
}
